package hn.security.message;

import hn.security.constant.SecurityConstant;

import java.io.Serializable;


public class SecurityResponse<T> implements Serializable {

    protected String statusCode;
    protected String promptInfo;

    protected T data;
    protected String requestId;
    protected String spendTime;

    public static <T> SecurityResponse<T> success(T t) {
        SecurityResponse securityResponse = new SecurityResponse();
        securityResponse.setStatusCode(SecurityConstant.SUCCESS.getCode());
        securityResponse.setPromptInfo(SecurityConstant.SUCCESS.getInfo());
        securityResponse.setData(t);
        return securityResponse;

    }

    public static SecurityResponse failure(SecurityConstant securityConstant) {
        SecurityResponse securityResponse = new SecurityResponse();
        securityResponse.setStatusCode(securityConstant.getCode());
        securityResponse.setPromptInfo(securityConstant.getInfo());
        return securityResponse;
    }

    /**
     * 处理未知错误传入错误信息
     *
     * @param promptInfo
     * @return
     */
    public static SecurityResponse failure(String promptInfo) {
        SecurityResponse securityResponse = new SecurityResponse();
        SecurityConstant securityConstant = SecurityConstant.FAILURE;
        if (promptInfo != null) {
            securityResponse.setPromptInfo(promptInfo);
        } else {//如果错误信息为空就赋值返回码的中文提示
            securityResponse.setPromptInfo(securityConstant.getInfo());
        }
        securityResponse.setStatusCode(securityConstant.getCode());
        return securityResponse;
    }


    public String getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(String statusCode) {
        this.statusCode = statusCode;
    }

    public String getPromptInfo() {
        return promptInfo;
    }

    public void setPromptInfo(String promptInfo) {
        this.promptInfo = promptInfo;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }


    public String getSpendTime() {
        return spendTime;
    }

    public void setSpendTime(String spendTime) {
        this.spendTime = spendTime;
    }

}
